<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:head>

	<h:outputStylesheet library="css" name="default.css" target="head" />

</h:head>
<body>
	<f:metadata>
		<f:event type="preRenderView" listener="#{userBean.istanzia()}" />
	</f:metadata>

	<h:form>
		<p:toolbar style="heigh:35px">
			<p:toolbarGroup align="left" style="margin-top:5px; margin-left:10px">
		Benvenuto #{userBean.name} <p:separator /> #{userBean.mail}
		
		</p:toolbarGroup>
			<p:toolbarGroup align="right" >
				<p:menuButton value="Opzioni">
					<p:menuitem value="Home" url="index.xhtml" icon="ui-icon-home" />
					<p:menuitem value="Visualizza Pacchetti" url="show_pacchetti.xhtml"
						icon="ui-icon-suitcase" />
					<p:menuitem value="Visualizza Prodotti" url="show_prodotti.xhtml"
						icon="ui-icon-clipboard" />
				</p:menuButton>
				<p:separator />
				<p:commandButton action="#{logBean.logout}" value="Logout"
					icon="ui-icon-power" />
			</p:toolbarGroup>
		</p:toolbar>
	</h:form>
<!--  
	<p:commandButton value="add" action="#{userBean.toggle()}"
		update="form" />
		
		<h:form id="form">
		<p:panel header="Registration Form" rendered="#{userBean.add}">
			<h:message for="registration_error_message" errorClass="error"
				id="registration_error_message" />
			<h:panelGrid columns="3" id="regGrid">
				<h:outputLabel for="email">Email:</h:outputLabel>
				<p:inputText id="email" value="#{registerBean.user.email}" />
				<p:message for="email" />

				<h:outputLabel for="firstName">First name:</h:outputLabel>
				<p:inputText id="firstName" value="#{registerBean.user.firstName}" />
				<p:message for="firstName" />

				<h:outputLabel for="lastName">Last name:</h:outputLabel>
				<p:inputText id="lastName" value="#{registerBean.user.lastName}" />
				<p:message for="lastName" />

				<h:outputLabel for="password">Password:</h:outputLabel>
				<p:password id="password" value="#{registerBean.user.password}"
					feedback="true" match="pwd2" label="Password" />
				<p:message for="password" />

				<h:outputLabel for="pwd2">Confirm Password:</h:outputLabel>
				<p:password id="pwd2" label="Confirm Password"
					value="#{registerBean.user.password}" />
				<h:inputHidden value="filler for the table" />

			</h:panelGrid>
			<p:commandButton value="Register"
				action="#{registerBean.registerAdmin()}" update="form, :list:users " />

		</p:panel>
	</h:form>
		-->
		
		<p:accordionPanel id="acc" activeIndex="-2" style="width:500px; margin-left:100px; margin-top:25px; margin-bottom:25px">  
    <p:tab title="Aggiungi Admin" >  
        <h:form id="form">
			<h:message for="registration_error_message" errorClass="error"
				id="registration_error_message" />
			<h:panelGrid columns="3" id="regGrid">
				<h:outputLabel for="email">Email:</h:outputLabel>
				<p:inputText id="email" value="#{registerBean.user.email}" />
				<p:message for="email" />

				<h:outputLabel for="firstName">First name:</h:outputLabel>
				<p:inputText id="firstName" value="#{registerBean.user.firstName}" />
				<p:message for="firstName" />

				<h:outputLabel for="lastName">Last name:</h:outputLabel>
				<p:inputText id="lastName" value="#{registerBean.user.lastName}" />
				<p:message for="lastName" />

				<h:outputLabel for="password">Password:</h:outputLabel>
				<p:password id="password" value="#{registerBean.user.password}"
					feedback="true" match="pwd2" label="Password" />
				<p:message for="password" />

				<h:outputLabel for="pwd2">Confirm Password:</h:outputLabel>
				<p:password id="pwd2" label="Confirm Password"
					value="#{registerBean.user.password}" />
				<h:inputHidden value="filler for the table" />

			</h:panelGrid>
			<p:commandButton value="Register" icon="ui-icon-person"
				action="#{registerBean.registerAdmin()}" update="regGrid, :list:users" />
				</h:form>
    </p:tab>  
</p:accordionPanel>  
	
	<div >
		<h:form id="list">
			<p:dataTable id="users" var="usr" value="#{userBean.getAllUsers()}">

				<f:facet name="header">  
			Elenco Utenti
			
		</f:facet>
				<p:column headerText="Nome" style="width:24%" filterBy="firstName"
					filterMatchMode="contains">
					<h:outputText value="#{usr.firstName}" />
				</p:column>

				<p:column headerText="Cognome" style="width:24%" filterBy="lastName"
					filterMatchMode="contains">
					<h:outputText value="#{usr.lastName}" />
				</p:column>

				<p:column headerText="Impiegato" style="width:24%">
					<p:selectBooleanCheckbox value="#{!(usr.isClient)}" disabled="true" />
				</p:column>

				<p:column headerText="eMail" style="width:24%" filterBy="email"
					filterMatchMode="contains">
					<h:outputText value="#{usr.email}" />
				</p:column>

				<p:column style="width:4%">
					<!--  <p:commandButton id="delete_user"
						oncomplete="PF('usrDialog').show()" icon="ui-icon-closethick"
						title="View">
						<f:setPropertyActionListener value="#{usr.email}"
							target="#{userBean.selectedUser}" />
					</p:commandButton> -->
					<p:commandButton id="delete_user2"
						action="#{userBean.delUser2(usr.email)}" icon="ui-icon-closethick"
						title="View" update="users">
					</p:commandButton>
				</p:column>

			</p:dataTable>
		</h:form>
	</div>
	<!--  
	<p:dialog header="User Detail" widgetVar="usrDialog" resizable="false"
		id="usrDlg" showEffect="fade" hideEffect="fade" modal="true">
		<p:panel>
  			Vuoi eliminare l'utente?
  			<p:commandButton value="SI" action="#{userBean.delUser()}" />
			<p:commandButton value="NO" update="" />
		</p:panel>
		<h:panelGrid id="display" columns="2" cellpadding="4"
			style="margin:0 auto;">

		</h:panelGrid>

	</p:dialog>-->

</body>
</html>